<template>
  <h1>一个人的信息</h1>
  <h2>姓名：{{ person.name }}</h2>
  <h2 v-show="person.age">年龄：{{ person.age }}</h2>
  <h2 v-show="person.sex">性别：{{ person.sex }}</h2>
  <h3>工种：{{ person.job.type }}</h3>
  <h3>工资：{{ person.job.salary }}</h3>
  <h3>测试c：{{ person.job.a.b.c }}</h3>
  <div v-for="(h, index) in person.hobbies" :key="index">{{ h }}</div>
  <button @click="changeInfo">修改人的信息</button>
  <button @click="addSex">添加一个sex属性</button>
  <button @click="deleteAge">删除age属性</button>
</template>

<script>
import { reactive } from "vue";
export default {
  name: "App",
  setup() {
    let person = reactive({
      name: "张三",
      age: 18,
      job: {
        type: "前端开发工程师",
        salary: "30k",
        a: {
          b: {
            c: 666,
          },
        },
      },
      hobbies: ["唱", "跳", "RAP", "篮球"],
    });

    function changeInfo() {
      console.log(person.job);
      person.name = "李四";
      person.age = 19;
      person.job.salary = "60k";
      person.job.a.b.c = 999;
      person.hobbies[0] = "睡觉";
    }

    function addSex() {
      person.sex = "男";
    }

    function deleteAge() {
      delete person.age;
    }

    return {
      person,
      changeInfo,
      addSex,
      deleteAge,
    };
  },
};
</script>
